var Adv_skd=require("./Adv_skd3")

cc.Class({
  extends: cc.Component,
  properties: {
    signJsonFile: cc.JsonAsset,
    baseSignItem: cc.Node,
    sevenSignItem: cc.Node,
    signPanel: cc.Node,
    signBtnPanel: cc.Node,
    signBtn: cc.Node,
    signAdBtn: cc.Node,
    finishBtn: cc.Node
  },
  initBy: function () {
        Adv_skd.default.instance.hideAllAdv();
    
     Adv_skd.default.instance.showInterstitialAd();
    Adv_skd.default.instance.showGridAdTop();
    cc.UISign = this;
    this.signJson = this.signJsonFile.json;
    this.isLookAd = false;
    cc.pvz.PlayerData.checkAndResetSign();
    this.SignData = cc.pvz.PlayerData.getSignData();
    this.refreshSignBtn();
    this.initUIInfo();
  },
  initUIInfo: function () {
    var e = this;
    this.signItemList = [this.baseSignItem.getComponent("SignItem")];
    for (var t = 0; t < 5; t++) {
      var i = cc.instantiate(this.baseSignItem);
      i.parent = this.signPanel.children[t + 1];
      this.signItemList.push(i.getComponent("SignItem"));
    }
    this.signItemList.push(this.sevenSignItem.getComponent("SignItem"));
    var o = this.SignData.signDay;
    var a = o % 7;
    this.useSignDay = 0 == a ? 7 : a;
    var c = function () {
      var t = s + 1;
      var i = o <= 7 ? t : 100 + t;
      var a = e.signJson.find(function (e) {
        return e.ID == i;
      });
      e.signItemList[s].initSignItem(t, a, e.useSignDay);
    };
    for (var s = 0; s < 7; s++) {
      c();
    }
  },
  refreshSignBtn: function () {
    this.isRewardSign = this.SignData.isReward;
    this.signBtnPanel.active = !this.isRewardSign;
    this.finishBtn.active = this.isRewardSign;
    this.signBtn.active = 0 == cc.player.signStatus;
    this.signAdBtn.active = 1 == cc.player.signStatus;
  },
  onSignLogic: function (e) {
    undefined === e && (e = false);
    if (e) {
      cc.pvz.PlayerData.updateSignStatus(2);
      cc.pvz.PlayerData.finishSignReward();
    } else {
      cc.pvz.PlayerData.updateSignStatus(1);
    }
    this.signItemList[this.useSignDay - 1].onGetSignReward(e);
    this.refreshSignBtn();
  },
  onClickSign: function () {
    if (!this.isLookAd) {
      if (this.isRewardSign) {
        cc.UIRoot.showToast("今日已签到");
      } else {
        this.onSignLogic(false);
      }
    }
  },
  onClickSignAd: function () {
    var e = this;
    if (!this.isLookAd) {
      if (this.isRewardSign) {
        cc.UIRoot.showToast("今日已签到");
      } else {
        this.isLookAd = true;
        cc.pvz.AdUtils.showAdRewardVideo(cc.pvz.GameConfig.AdType.再签一次, function (t) {
          e.onAdClose(t);
        });
      }
    }
  },
  onAdClose: function (e) {
    this.isLookAd = false;
    e && this.onSignLogic(true);
  },
  onClickEndSign: function () {
    cc.popupManager.showToast("今日已签到");
  },
  onCloseUI: function () {
    
    Adv_skd.default.instance.hideAllAdv();

    this.isLookAd || cc.popupManager.removePopup(this);
  }
});